<!-- 预约审批操作 -->
<template>
	<view class="main-box">
		<view class="main-box-item h100">
			<view class="box-info-label">
				审批意见
			</view>
			<view class="box-info-value">
				<uni-easyinput type="textarea" class="textarea" v-model="formData.suggestion" placeholder="请填写审批意见" />
			</view>
		</view>
		<view class="btn-box">
			<button class="ml10 mr10 btn1" type="warn" size="mini" @click="doSubmit('0')"> 同意 </button>
			<button class="ml10 mr10 btn2" type="warn" size="mini" plain="true" @click="doSubmit('3')"> 拒绝 </button>
		</view>
		<!-- 提示信息弹窗 -->
		<uni-popup ref="message" type="message">
			<uni-popup-message :type="msgType" :message="messageText" :duration="5000"></uni-popup-message>
		</uni-popup>
	</view>
</template>

<script>
	import { Platform } from '@/static/config.js';
	import {FormatDateTime} from '@/common/util.js'
	import request from '@/common/request.js';
	import qs from 'qs'
	export default {
		props: ['item'],
		data() {
			return {
				formData: {},
				// 提示信息弹窗
				type: 'center',
				msgType: 'success',
				messageText: '这是一条成功提示',
			}
		},
		mounted() {
		},
		methods: {
			// 提交审批信息
			doSubmit(info) {
				let _self = this;
				_self.formData.bookingid = _self.item.bookingid;
				_self.formData.state = info;
				uni.showLoading({
					title: '提交中...',
					mask: false
				});
				request({
					url: Platform.api_requestUrl + '/stp-booking/bookingApproval',
					data: _self.formData,
					method: 'POST',
				}).then(response => {
					uni.hideLoading();
					if (response.code == 200) {
						_self.messageToggle('success', '提交成功');
						//大华系统提交预约信息
						info=='0' && _self.getAccessToken();
						uni.navigateBack();
					} else {
						_self.messageToggle('error', response.message || '提交失败');
					}
				}).catch(error => {
					uni.hideLoading();
					uni.showModal({
						content: '提交失败',
						showCancel: false
					})
				});
			},
			messageToggle(type, msg) {
				this.msgType = type
				this.messageText = msg
				this.$refs.message.open()
			},
			getAccessToken() {
				let pa = {
				  "requestHeader": {},
				  "requestMethod": "GET",
				  "requestUrl": "https://192.168.27.170:4430/ipms/subSystem/generate/token?userName=system" 
				}
				request({
					url: Platform.api_requestUrl + '/request/httpsrequest',
					data: pa,
					method: 'POST',
				}).then(res => {
					if (res && res.code == 200 && res.data && res.data.success) {
						//大华系统提交预约信息
						this.bookingTodahua(res.data.data.accessToken)
					} else {
						this.messageToggle('error', res.message || '提交数据到大华岗亭系统失败');
					}
				}).catch(error => {
					uni.showModal({
						content: '提交数据到大华岗亭系统失败',
						showCancel: false
					})
				});
			},
			bookingTodahua(token) {
				let _self = this;
				let baseUrl = 'https://192.168.27.170:4430/ipms/carReservation/add'
				let param = {
					// id:"",
					carNum: this.item.carcode,//车牌号码
					parkingLotCode:'',//停车场编号
					sluiceChns:'1000001$14$0$0',//进出口通道---默认 东门入口_1
					// serialNumber:'',//预约单号
					consumerName:this.item.driver,//车主姓名
					telNumber:this.item.contactphone,//车主联系方式
					enterModel:'1',//入场模式
					exitModel:'1',//出场模式
					startTimeStr:FormatDateTime(this.item.intime),//入场有效起始时间
					endTimeStr:FormatDateTime(this.item.intime),//入场有效截至时间
					// notifyUrl:'',//车辆进出回调接口
				}
				let commonpa = {
					"requestHeader": { 
						"accessToken": token,
						"Content-Type":"application/json",
						"Charset":"UTF-8"
					},
					"requestMethod": "POST",
					"outputStr": JSON.stringify(param),
					"requestUrl": baseUrl //+ '?' + qs.stringify(param)
				}
				request({
					url: Platform.api_requestUrl + '/request/httpsrequest',
					data: commonpa,
					method: 'POST',
				}).then(res => {
					if (res && res.code == 200 && res.data && res.data.success) {
						// _self.messageToggle('success', '提交成功');
					} else {
						_self.messageToggle('error', res.message|| res.data.errMsg || '提交数据到大华岗亭系统失败');
					}
				}).catch(error => {
					uni.showModal({
						content: '提交数据到大华岗亭系统失败',
						showCancel: false
					})
				});
			},
		}
	}
</script>

<style lang='scss' scoped>
	.main-box {
		/* flex: 1; */
		overflow: scroll;
		background: #e9e9e9;
		height: 100%;
		padding-top: 10rpx;

		.main-box-item {
			display: flex;
			align-items: center;
			height: 50px;
			background: #FFFFFF;
			/* box-shadow: 0px 2px 5px #F0F0F0; */
			/* border-radius: 4px; */
			vertical-align: middle;
			padding: 0px 10px;
			border-bottom-color: #E6E6E6;
			border-bottom-style: solid;
			border-bottom-width: 0.5px;

			.box-info-label {
				margin: 0 10px;
				font-size: 14px;
				font-weight: 500;


			}

			.box-info-value {
				margin-left: 10px;
				font-size: 14px;
				color: #B5B5B5;
				flex: 1;
				display: flex;
				.textarea {
					height: 80px;
					flex: 1;
					display: flex;
					flex-direction: column;
					align-items: baseline;
					justify-content: center;
				}

				.img {
					height: 38rpx;
					width: 38rpx;
					margin-left: 20rpx;
				}

			}

			.status {
				float: right;
				font-size: 22rpx;
				text-align: center;
				broder: 2rpx;
				border-width: 1rpx;
				border-style: solid;
				height: 38rpx;
				width: 80rpx;
				border-radius: 10rpx;
			}
		}

		.btn-box {
			background: #FFFFFF;
			padding: 15px 0;
			display: flex;
			justify-content: space-around;

			.btn1 {
				width: 90%;
				background-color: #07D2C6;
			}

			.btn2 {
				width: 90%;
				color: #FF2600;
				border: 1px solid #FF2600;
			}
		}
	}
</style>
